package com.wnxy.sddfp.payback.mapper;

import com.wnxy.sddfp.payback.entity.BorrowerPayPlan;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 借款人还款计划 Mapper 接口
 * </p>
 *
 * @author Jet
 * @since 2023-05-17
 */
public interface BorrowerPayPlanMapper extends BaseMapper<BorrowerPayPlan> {

    /**
     * 查询到期的还款计划, 且payStatus是未还款
     * @param date
     * @return
     */
    @Select("SELECT * FROM borrower_pay_plan WHERE pay_status=0 AND DATE_FORMAT(should_pay_date,'%Y-%m-%d')=#{date}")
    List<BorrowerPayPlan> findPayPlanByDate(String date);

    /**
     * 查询到期的还款计划，分片处理
     */
    @Select("SELECT * FROM borrower_pay_plan WHERE pay_status=0 " +
            "AND DATE_FORMAT(should_pay_date,'%Y-%m-%d')=#{date} and MOD(id,#{shardTotal})=#{shardIndex}")
    List<BorrowerPayPlan> findPayPlanByDateSharding(
            @Param("date") String date, @Param("shardIndex") int shardIndex, @Param("shardTotal") int shardTotal);
}
















